#!/bin/bash

# 测试读取配置文件
# config_file="/mnt/sdc/opt/ems-archive/config/db.properties"

# sed -n '{
#     p
# }' $config_file

# 参考：
# https://www.baeldung.com/linux/script-parsing-properties-file
# https://www.baeldung.com/linux/trim-whitespace-bash-variable

file="/opt/ems-archive/config/config.properties"

# while IFS='=' read -r key value
# do
#     key=$(echo $key | tr '.' '_')
#     eval ${key}=\${value}
# done < "$file"



echo "IFS: $IFS"
while IFS='=' read -r key value
do
    key=$(echo $key | tr '.' '_')
    # 如果 key 不为空，且不是以 "#" 开头
    if [[ -n "$key" ]] && [[ ! "$key" =~ ^\# ]]; then
        # value 去掉两边空格
        value=$(echo "$value" | sed -e 's/[[:space:]]*//g')
        # 动态变量
        eval ${key}=\${value}
    fi    
done < "$file"

echo "taos_db_user: |$(echo $taos_db_user | xargs )|"
echo "taos_db_pwd: |${taos_db_pwd}|"
echo "mysql_db_user: |${mysql_db_user}|"
echo "mysql_db_pwd: |${mysql_db_pwd}|"
echo "IFS: $IFS"